package com.grts.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.grts.pojo.MajorBean;
import com.grts.pojo.t_student;
import com.grts.service.IMajorService;
import com.grts.service.impl.MajorServiceImpl;
import com.grts.utils.PageModel;

@Controller
@RequestMapping("/major")
public class MajorController {
	@Resource
	private IMajorService ms;
	@RequestMapping("/queryAll_Major")
	public String queryAll(Map<String,Object> map){
		List<MajorBean> majors = ms.queryAll();
		map.put("pageModel",majors);	
		return "../major/major";
	}
	@RequestMapping("/queryByName_Major")
	public String queryByName(Map<String,Object> map,String mname){
		
		List<MajorBean> majors = ms.queryByName(mname);
		map.put("mname",mname);
		map.put("pageModel",majors);	
		return "../major/major1";
	}
	@RequestMapping("/add_Major")
	public String add(MajorBean major,Map map){
			MajorBean mj = ms.selectByPrimaryKey(major.getMid());
			List<MajorBean> majors = ms.queryAll();
			map.put("pageModel",majors);
			map.put("major", mj);
		return "../major/addOrUpdate";
	}
	@RequestMapping("/addOrUpdate_Major")
	public String addOrUpdate(MajorBean major){
		if (major.getMid() == null) {
			ms.insert(major);
		}else{
			ms.updateByPrimaryKey(major);
		}
			
		return "redirect:queryAll_Major";
	}
	@RequestMapping("/toAddOrUpdate_Major")
	public String toAddOrUpdate(@RequestParam(name="mid",required=false)int mid){
		
		return "../major";
	}
	@RequestMapping("/delete_Major")
	public String delete(@RequestParam(name="mid",required=false)int mid){
		ms.deleteByPrimaryKey(mid);
		return "redirect:queryAll_Major";
	}
}
